/**
 * 分享工具
 * Created by duwei on 2018/5/28.
 */
var ShareUtil = {
    /**
     * 分享类型
     */
    ShareType: {
        SCREENSHOT: 1,
        PLAYBACKID: 2,
        CLUB: 3,
        ROOMID: 4,
        GAME: 5,
        ZHANJI: 6
    },
    /**
     * 分享平台
     */
    SharePlatForm: {
        WeiXin: 'weixin',
        WeiXinQuan: 'weixinqian',
        XiaoChengXu: 'xiaochengxu',
        QQ: 'qq',
        DingDing: 'dingding',
        LiaoBai: 'liaobei',
        XianLiao: 'xianliao'
    },
    /**
     * 分享俱乐部
     * @param clubData
     * @param shareType 分享平台：如果传值，直接分享此平台
     * @constructor
     */
    ShareClub: function (clubData, shareType) {
        showWindow("ShareWindow", {type: this.ShareType.CLUB, clubData: clubData, shareType: shareType});
    },
    /**
     * 分享截图
     * @param {Object} screenshot
     * @param {ShareUtil.SharePlatForm | String} [shareType] 分享平台：如果传值，直接分享此平台
     * @public
     */
    SharePic: function (screenshot, shareType) {
        screenshot.retain();
        showWindow("ShareWindow", {type: this.ShareType.SCREENSHOT, screenshot: screenshot, shareType: shareType});
    },
    /**
     * 分享图片
     * @param screenshot
     * @param shareType
     * @constructor
     */
    ShareImage: function (node, shareType) {


        showWindow("ShareWindow", {type: this.ShareType.SCREENSHOT, screenshot: screenshot, shareType: shareType});
    },
    SharePic1: function (screenshot, shareType) {
        showWindow("ShareType", {type: this.ShareType.SCREENSHOT, screenshot: screenshot, shareType: shareType});
    },
    /**
     * 分享回放码
     * @param playbackId
     * @param shareType 分享平台：如果传值，直接分享此平台
     */
    SharePlaybackId: function (playbackId, shareType) {
        showWindow("ShareWindow", {type: this.ShareType.PLAYBACKID, playbackId: playbackId, shareType: shareType});
    },
    /**
     * 分享游戏
     * @param gameDescribe
     * @param shareType 分享平台：如果传值，直接分享此平台
     * @constructor
     */
    ShareGame: function (gameDescribe, shareType, showpyq) {
        showWindow("ShareWindow", {
            type: this.ShareType.GAME,
            gameDescribe: gameDescribe,
            shareType: shareType,
            showpyq: showpyq
        });
    },
    /**
     * 分享房间ID
     * @param roomid
     * @param wanfaDesp
     * @param maxNum
     * @param cunNum
     * @param shareType 分享平台：如果传值，直接分享此平台
     * @constructor
     */
    ShareRoomId: function (roomid, wanfaDesp, maxNum, cunNum, shareType) {
        showWindow("ShareWindow", {
            type: this.ShareType.ROOMID,
            roomid: roomid,
            wanfaDesp: wanfaDesp,
            maxNum: maxNum,
            cunNum: cunNum,
            shareType: shareType
        });
    },
    /**
     * 分享房间ID
     * @param roomid
     * @param wanfaDesp
     * @param maxNum
     * @param cunNum
     * @param shareType 分享平台：如果传值，直接分享此平台
     * @param ownerUid 字牌需要传入ownerUid以保证数据正确
     * @constructor
     */
    ShareZhanJi: function (roomid, uid1, uid2, screenshot, fenshu, shareType, ownerUid) {
        showWindow("ShareWindow", {
            type: this.ShareType.ZHANJI,
            roomid: roomid,
            uid1: uid1,
            uid2: uid2,
            screenshot: screenshot,
            fenshu: fenshu,
            shareType: shareType,
            ownerUid: ownerUid
        });
    },
    /**
     * 复制房间号
     * @constructor
     */
    CopyRoomId:function () {
        var parts = decodeURIComponent(gameData.wanfaDesp).split(',');
        parts.splice(0, 1);
        var shareText = "【" + app.appName + "】\n" + mapId2Name(gameData.mapId) + "\n房号: " + ToDBC(gameData.roomId) + "\n"
            + (parts.length ? parts.join(', ') + ', ' : "") + "速度来啊！";

        var url = app.shareUrl + '?roomid=' + gameData.roomId;
        var MWSign = gameData.roomId ^ gameData.ownerUid;
        var MWArea = app.area;
        if (gameData.link == 2) {
            url = url + "&area=" + MWArea + "&sign=" + MWSign + "&details=true" + "#";
        }
        shareText += url;
        cc.log(shareText);
        DeviceUtil.savePasteBoard(shareText);
        showToast("您的房间信息已复制，请粘贴至微信处分享");
    }
};